package com.winchain.chainbill.bill.biz.send.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICallback;
import com.shell.framework.command.ICommand;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.base.service.CbSndService;
import com.winchain.chainbill.bill.biz.Bill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillSndCmd implements ICommand<Bill<CbSnd>>, ICallback<Bill<CbSnd>, AcctTxRec> {
	@Autowired
	private CbSndService cbSndService;

	public boolean execute(CommandContext<Bill<CbSnd>> context) throws Exception {
		CbRec record = ((Bill) context.getSource()).getRec();
		CbSnd send = (CbSnd) ((Bill) context.getSource()).getSource();
		if (send != null) {
			send.setOptSeq(record.getOptSeq());
			this.cbSndService.saveOrUpdate(send);
		}
		return false;
	}

	public boolean callback(CallbackContext<Bill<CbSnd>, AcctTxRec> context) throws Exception {
		execute(context);
		return false;
	}
}
